#!/usr/bin/env python

import sys

import matplotlib.pyplot as plt

from nw_sim_interpolation import DEGREE, interpolate_learn, interpolate_apply


def parse_input():
    x = []
    y = []
    for line in sys.stdin:
        spl = line.split()
        x.append(float(spl[0]))
        y.append(float(spl[1]))
    return x, y

def main():

    x, y = parse_input()

    coeffs = interpolate_learn(x, y)
    print coeffs
 
    # create a polynomial using coefficients
    f = interpolate_apply(coeffs)

    # for plot, estimate y for each observation time
    y_est = map(f, x)
 
    # create plot
    plt.plot(x, y, '.', label = 'original data', markersize=5)
    plt.plot(x, y_est, 'o-', label = 'estimate', markersize=1)
    plt.xlabel('Length of sequences')
    plt.ylabel('Predicted parameter')
    plt.title('least squares fit of degree %i' % DEGREE)
    #plt.savefig('sample.png')
    plt.show()
    plt.clf()


if __name__ == "__main__":
    main()

